package com.cjq.goods.controller;

import com.cjq.common.domain.Classify;
import com.cjq.common.domain.Goods;
import com.cjq.common.domain.request.GoodsReq;
import com.cjq.common.domain.response.GoodsRes;
import com.cjq.common.result.PageResult;
import com.cjq.common.result.Result;
import com.cjq.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    /**
     * 通过ID查询
     * @param id
     * @return
     */
    @GetMapping("/findById/{id}")
    public Result<Goods> findById(@PathVariable Long id){
        return goodsService.findById(id);
    }

    /**
     * 商品列表
     * @param goodsReq
     * @return
     */
    @PostMapping("/goodsList")
    public Result<PageResult<GoodsRes>> goodsList(@RequestBody GoodsReq goodsReq){
        Result<PageResult<GoodsRes>> result = goodsService.goodsList(goodsReq);
        return result;
    }

    /**
     * 分类
     * @return
     */
    @GetMapping("/classifyList")
    public Result<List<Classify>> classifyList(){
        return goodsService.classifyList();
    }

    /**
     * 添加
     * @param goods
     * @return
     */
    @PostMapping("/save")
    public Result save(@RequestBody Goods goods){
        return goodsService.save(goods);
    }

    /**
     * 修改
     * @param goods
     * @return
     */
    @PutMapping("/update")
    public Result update(@RequestBody Goods goods){
        return goodsService.update(goods);
    }
}
